import React from 'react'
import GoBackLayout from "../layouts/GoBackLayout/GoBackLayout";
import {withRouter,} from 'react-router-dom'
import CustomButton from "../shared-components/CustomButton/CustomBotton";
import LocalStorageService from "../utils/LocalStorageService";
import {jubaoPlanReq, zanPlanReq} from "../apis/goApis";
import {Toast} from "antd-mobile";
import constants from "../utils/constants";

class PlanJubao extends React.Component {

    constructor(props) {
        super(props)
        this.uid = LocalStorageService.get('userid')
        this.state = {
            txt: '',
        }
    }

    submit = () => {
        const plan = this.props.location.state
        const Schemeid = plan.id
        const Uid = this.uid
        jubaoPlanReq({
            Schemeid,
            Uid,
            txt: this.state.txt,
        })
            .then(res => {
                if (res.data.ok === 1) {
                    Toast.success('举报成功', 0.5)
                    setTimeout(() => {
                        this.props.history.goBack()
                    }, 500)
                } else {
                    Toast.fail(constants.ErrorCode[res.data.err], 0.5)
                }
            })
    }

    render() {
        return <GoBackLayout
            history={this.props.history}
            mainTitle="举报"
        >

            <div
                className="pd-12"
                style={{background: '#fff',}}
            >
                <p className="mg-b-12px">举报理由</p>
                <div
                    className="flex-center-align-center mg-b-12px"
                    style={{
                        position: 'relative',
                    }}
                >
                    <textarea
                        value={this.state.txt}
                        onChange={e => this.setState({txt: e.target.value,})}
                        rows="10"
                        style={{
                            background: '#F8F8F8',
                            width: '100%',
                            resize: 'none',
                            padding: '8px 12px',
                        }}
                        maxLength={200}
                        placeholder="请填写您的举报理由…"
                    />
                    <p
                        style={{
                            position: 'absolute',
                            bottom: '12px',
                            right: '12px'
                        }}
                    >
                        {this.state.txt.length}/200
                    </p>
                </div>
                <CustomButton
                    bg={"#FFA500"}
                    onClick={this.submit}
                >
                    提交
                </CustomButton>
            </div>

        </GoBackLayout>
    }
}

export default withRouter(PlanJubao)